package com.test.demo.sentinel;

import com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect;
import com.test.demo.sentinel.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author laigl
 * @ClassName
 * @Description
 * @Date 2020/01/07 18:01
 */
@SpringBootApplication
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    // 注解支持的配置Bean
    @Bean
    public SentinelResourceAspect sentinelResourceAspect() {
        return new SentinelResourceAspect();
    }

    @RestController
    static class TestController {

        @Autowired
        private TestService testService;

        @GetMapping("test")
        public String test() {
            /**
             * nacos 中，json格式，内容如下
             [
             {
             "resource": "/test",
             "limitApp": "default",
             "grade": 1,
             "count": 2,
             "strategy": 0,
             "controlBehavior": 0,
             "clusterMode": false
             }
             ]
             */
            testService.doSomeThing();
            return "test";
        }
    }

}
